package com.spa.interfaces.admin;

import com.spa.application.command.admin.MassagistWithdrawPayCommand;
import com.spa.application.command.admin.ShopWithdrawAuditCommand;
import com.spa.application.command.admin.ShopWithdrawPayCommand;
import com.spa.application.dto.PageResult;
import com.spa.application.dto.admin.*;
import com.spa.application.dto.admin.ShopWithdrawOrderListDTO;
import com.spa.application.query.admin.AdminWithdrawOrderDetailQuery;
import com.spa.application.query.admin.MassagistWithdrawRecordDetailQuery;
import com.spa.application.query.admin.MessagistWithdrawListQuery;
import com.spa.application.query.admin.ShopWithdrawListQuery;
import com.spa.application.query.admin.ShopWithdrawRecordDetailOrderListQuery;
import com.spa.application.service.admin.AdminWithdrawApplicationService;
import com.spa.infrastructure.common.ResponseMessage;
import com.spa.infrastructure.util.UrlUtil;
import com.spa.interfaces.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("admin/withdraw")
public class AdminWithdrawController extends BaseController {

    @Autowired
    private AdminWithdrawApplicationService adminWithdrawApplicationService;

    @PostMapping("massagist/page")
    public ResponseMessage<PageResult<MessagistWithdrawList4AdminDTO>> massagistPage(@RequestBody MessagistWithdrawListQuery query) {
        return responseHelper.success(adminWithdrawApplicationService.massagistPage(query));
    }

    @PostMapping("exportWithdrawMassagist")
    public void exportWithdrawMassagist(HttpServletResponse response,@RequestBody MessagistWithdrawListQuery query) throws Exception {
        exportQueryResult(response, adminWithdrawApplicationService.massagisList(query), "技师提现列表", "技师提现列表", MessagistWithdrawExportDTO.class);
    }

    @PostMapping("payForMassagist")
    public ResponseMessage payForMassagist(@Validated @RequestBody MassagistWithdrawPayCommand command) {
        adminWithdrawApplicationService.payForMassagist(command);
        return responseHelper.success();
    }

    @PostMapping("payForMassagist/v2")
    public ResponseMessage payForMassagistV2(@Validated @RequestBody MassagistWithdrawPayCommand command) {
        command.setCredentials(UrlUtil.handleUrl(command.getCredentials(), ","));
        adminWithdrawApplicationService.payForMassagist(command);
        return responseHelper.success();
    }

    @PostMapping("shop/page")
    public ResponseMessage<PageResult<ShopWithdrawList4AdminDTO>> shopPage(@RequestBody ShopWithdrawListQuery query) {
        return responseHelper.success(adminWithdrawApplicationService.shopPage(query));
    }

    @PostMapping("exportWithdrawShop")
    public void exportWithdrawShop(HttpServletResponse response,@RequestBody ShopWithdrawListQuery query) throws Exception {
        exportQueryResult(response, adminWithdrawApplicationService.shopWithdrawList(query), "门店提现列表", "门店提现列表", ShopWithdrawExportDTO.class);
    }

    @PostMapping("audit")
    public ResponseMessage audit(@Validated @RequestBody ShopWithdrawAuditCommand command) {
        adminWithdrawApplicationService.audit(command);
        return responseHelper.success();
    }

    @PostMapping("payForShop")
    public ResponseMessage payForShop(@Validated @RequestBody ShopWithdrawPayCommand command) {
        adminWithdrawApplicationService.payForShop(command);
        return responseHelper.success();
    }

    @PostMapping("payForShop/v2")
    public ResponseMessage payForShopV2(@Validated @RequestBody ShopWithdrawPayCommand command) {
        command.setCredentials(UrlUtil.handleUrl(command.getCredentials(), ","));
        adminWithdrawApplicationService.payForShop(command);
        return responseHelper.success();
    }

    @PostMapping("massagistOrderList")
    public ResponseMessage<PageResult<MassagistOrderListWithdrawDTO>> massagistOrderList(@Validated @RequestBody MassagistWithdrawRecordDetailQuery query) {
        return responseHelper.success(adminWithdrawApplicationService.MassagistWithdrawOrderList(query));
    }

    @PostMapping("withdrawRecordDetailOrderList")
    public ResponseMessage<PageResult<ShopWithdrawOrderListDTO>> withdrawRecordDetailOrderList(@Validated @RequestBody ShopWithdrawRecordDetailOrderListQuery query) {
        return responseHelper.success(adminWithdrawApplicationService.ShopWithdrawOrderList(query));
    }

    @PostMapping("orderDetail")
    public ResponseMessage<AdminWithdrawOrderDetailDTO> orderDetail(@Validated @RequestBody AdminWithdrawOrderDetailQuery query) {
        return responseHelper.success(adminWithdrawApplicationService.orderDetail(query));
    }

}
